class Solution(object):
    def pivotIndex(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        n = len(nums)
        pre = [0] * n
        pre[0] = nums[0]
        for i in range(n):
            pre[i] = pre[i - 1] + nums[i]
        for i in range(n):
            if pre[-1] - pre[i] == pre[i] - nums[i]:
                return i
        return -1


data = Solution()
nums = [1, 7, 3, 6, 5, 6]
print(data.pivotIndex(nums))
